package com.e2a.examenenligne.ejb.serviceDAO;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.e2a.examenenligne.entities.Categorie;
import com.e2a.examenenligne.entities.Examen;


@Stateless
@LocalBean
public class ServiceExamen {

  @PersistenceContext
  EntityManager em;
 

    public ServiceExamen() {
    }
    
    public List<Examen> getAllExamens(){
  	  Query q= em.createNamedQuery("findAllExamens");
  	  return q.getResultList();
    }
    public List<Examen> getAllExamensByCategorie(Categorie c){
    	  Query q= em.createNamedQuery("findExamenByCategorie");
    	  q.setParameter("categorie", c);
    	  return q.getResultList();
      }
    public List<Examen> getAllExamensById(int id){
  	  Query q= em.createNamedQuery("findExamenById");
	  q.setParameter("id", id);
  	  return q.getResultList();
    }
   public Examen createExamen (Examen exam){
	   em.persist(exam);  
	   return exam;
   }
}
